package com.Dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.bean.Student;
import com.jdbc.ConnectionUtil;



public class StudentDao {
	
	
	//查询学生信息
		public  static List<Student> queryStudentById(int id) throws ClassNotFoundException, SQLException {
			
			
			List<Student> listStudent = new ArrayList<Student>();
			Student student = null;  
	        // 获取数据库连接Connection对象  
			ConnectionUtil con = new ConnectionUtil();
	        Connection conn = con.getConnection();  
	        // 根据用户名及密码查询用户信息  
	        String sql = "select * from student ";  
	        try {  
	            // 获取PreparedStatement对象  
	            PreparedStatement ps = conn.prepareStatement(sql);  
	            // 对SQL语句的占位符参数进行动态赋值  
	            //ps.setInt(1, id);
	            // 执行查询获取结果集  
	            ResultSet rs = ps.executeQuery();  
	            // 判断结果集是否有效  
	            while(rs.next()){  
	                // 实例化一个用户对象  
	            	student = new Student();  
	                // 对用户对象属性赋值  
	            	student.setId(rs.getInt("id"));  
	            	student.setName(rs.getString("name"));  
	            	student.setClassid(rs.getInt("classid")); 
	            	student.setTelephone(rs.getString("telephone")); 
	            	student.setCreditcard(rs.getString("creditcard")); 
	            	student.setPhotourl(rs.getString("photourl")); 
	            	student.setGiturl(rs.getString("giturl")); 
	            	listStudent.add(student);
	            }  
	            // 释放此 ResultSet 对象的数据库和 JDBC 资源  
	            rs.close();  
	            // 释放此 PreparedStatement 对象的数据库和 JDBC 资源  
	            ps.close();  
	        } catch (Exception e) {  
	            e.printStackTrace();  
	        }finally{  
	            // 关闭数据库连接  
	        	conn.close();  
	        }  
	        return listStudent;  
			
		}
		

}
